Feat/amm registry - #335
Open
0x-r4bbit wants to merge 5 commits into
Open
Conversation
Split the AMM UI's known-tokens/known-pools loading into two concerns: - reading raw JSON bytes from a source (`readConfigFileBytes`, currently a local file at TOKENS_CONFIG / AMM_POOLS_CONFIG), and - parsing those bytes into the UI list (`parseTokensJson` / `parsePoolsJson`). The parsers are now source-agnostic, so a remote payload can feed the exact same validation and shaping. No behavior change: the local-file env-var path is preserved, including the fail-soft / skip-malformed-entry semantics.
Introduce apps/amm/src/RegistryLoader, a QObject that owns the known-tokens / known-pools snapshot and serves it to the backend's QtRO slots. The JSON parsers move here; AmmUiBackend now reads tokenList/poolList/resolveTokens from the loader's snapshot instead of re-parsing the config files inline. Add the refresh plumbing the UI will drive: - PROP(int registryRevision READONLY) — bumped on every snapshot refresh so QML replicas re-fetch the lists. - SLOT(void refreshRegistry()) — manual re-load. No behavior change: the source is still the local TOKENS_CONFIG / AMM_POOLS_CONFIG files. This is Phase 2a of docs/amm-registry-plan.md; Phase 2b reshapes RegistryLoader::refresh() into the async remote (AMM_REGISTRY_URL) fetch — manifest + deployment guard + disk cache — with the same snapshot contract.
When no local TOKENS_CONFIG / AMM_POOLS_CONFIG is set, RegistryLoader now loads the known-tokens / known-pools from a remote GitHub registry named by AMM_REGISTRY_URL: an async QNetworkAccessManager fetch of a registry.json manifest, then the tokens.json / pools.json it points at (resolved relative to the manifest URL). - Stale-while-revalidate: the on-disk cache is served immediately and revalidated against the network (the manifest `timestamp` is the freshness key); a failed/offline fetch keeps the last cache. - Deployment guard: a manifest whose programIds don't match the app's deployment (from configAccount) is rejected; a manifest that omits programIds is trusted. - Precedence unchanged: local files replace the remote source when set; user custom tokens still merge on top. - registryRevision bumps on each snapshot update; SwapPage/PoolsPage/ LiquidityPage re-fetch on it. CMake links Qt6::Network. Add apps/amm/registry-sample/ — a manifest plus empty tokens.json / pools.json and a README — to exercise the remote path end to end (start with the empty case). Compile-verified via `nix build .#amm-ui`; not yet run end to end.
Replace the per-network manifest + separate tokens.json/pools.json with a single
Uniswap-token-list-style document: { networks:[{id,name,programIds}],
tokens:[{network,...}], pools:[{network,...}] }. RegistryLoader now fetches one
file, selects the active network, and filters entries to it.
- Active network = AMM_NETWORK (override) -> else the network whose programIds
match the connected deployment (configAccount) -> else the lone network. The
programIds match doubles as the deployment guard.
- Registry lives in-repo at artifacts/amm-registry.json (no separate repo yet);
remove apps/amm/registry-sample/.
- Rename setExpectedProgramIds -> setConnectedProgramIds (drives selection + guard);
add activeNetwork(). Local dev source (bare arrays) is unchanged.
setup-amm-testnet.sh now also writes tests/testnet/amm-registry.json — the seeded tokens/pools in the single-file multi-network registry shape (one "local" network with empty programIds so the lone-network rule auto-selects it; holding-agnostic tokens; a fresh timestamp each run). This lets the AMM_REGISTRY_URL path be exercised against the local sequencer without hosting anything — point AMM_REGISTRY_URL at the file with a file:// URL.
There was a problem hiding this comment.
Pull request overview
Adds an AMM “registry” configuration path to the AMM UI so known tokens/pools can be sourced either from existing local JSON files or from a single multi-network registry document (with a simple disk cache), and refreshes can propagate to QML via a revision counter.
Changes:
- Introduces
RegistryLoader(local-over-remote resolution, remote fetch + disk cache, network selection + deployment guard). - Wires
RegistryLoaderintoAmmUiBackendand exposesregistryRevision+refreshRegistry()so QML can re-fetch lists when the snapshot updates. - Updates testnet setup script to emit a single-file registry for exercising
AMM_REGISTRY_URL, and updates QML pages to reload lists whenregistryRevisionchanges.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| artifacts/amm-registry.json | Adds an on-repo registry JSON document/template. |
| apps/amm/tests/testnet/setup-amm-testnet.sh | Writes a test-only single-file registry and documents how to use AMM_REGISTRY_URL locally. |
| apps/amm/src/RegistryLoader.h | Declares new loader interface for registry-backed token/pool snapshots. |
| apps/amm/src/RegistryLoader.cpp | Implements local/remote loading, network selection, deployment checks, and disk caching. |
| apps/amm/src/AmmUiBackend.rep | Exposes registryRevision and refreshRegistry() over QtRO for QML consumers. |
| apps/amm/src/AmmUiBackend.h | Adds RegistryLoader member and new refreshRegistry() slot. |
| apps/amm/src/AmmUiBackend.cpp | Replaces direct file parsing with RegistryLoader snapshot and revision propagation. |
| apps/amm/qml/pages/SwapPage.qml | Reloads token list when registryRevision changes. |
| apps/amm/qml/pages/PoolsPage.qml | Reloads pool list when registryRevision changes. |
| apps/amm/qml/pages/LiquidityPage.qml | Reloads resolved tokens when registryRevision changes. |
| apps/amm/CMakeLists.txt | Adds RegistryLoader sources and links Qt Network. |
| apps/amm/.gitignore | Ignores test-generated amm-registry.json. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+9
to
+12
| class QNetworkAccessManager; | ||
| class QJsonArray; | ||
| class QJsonObject; | ||
|
|
| return true; | ||
| if (m_connectedAmm.isEmpty() && m_connectedToken.isEmpty()) | ||
| return true; | ||
| return amm == m_connectedAmm && token == m_connectedToken; |
Comment on lines
+326
to
+330
| QString RegistryLoader::cachePath() | ||
| { | ||
| return QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) | ||
| + QStringLiteral("/amm-registry-cache.json"); | ||
| } |
| POOLS_CONFIG_OUT="apps/amm/tests/testnet/amm-pools.json" | ||
|
|
||
| # Single-file multi-network registry (git-ignored, tests only) — the same tokens | ||
| # and pools in the remote-registry shape (see docs/amm-registry-plan.md), so the |
| "name": "Logos AMM registry", | ||
| "version": "0.1.0", | ||
| "timestamp": "2026-08-27T00:00:00Z", | ||
| "networks": [], |
gravityblast
approved these changes
Aug 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.